package com.gxa.saas.portal.controller.hhy;

import com.gxa.saas.core.entity.vo.hhy.GoodsClassifyVO;
import com.gxa.saas.core.entity.vo.hhy.MonthVO;
import com.gxa.saas.core.entity.vo.hhy.TimeAndMoneyVO;
import com.gxa.saas.core.entity.vo.hhy.TotalGoodsAndMoneyVO;
import com.gxa.saas.core.utils.JwtUtil;
import com.gxa.saas.portal.service.hhyservice.LookDataService;
import com.gxa.saas.portal.service.hhyservice.SelectShopIdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags="数据看板相关接口")
@RestController
@RequestMapping("/lookData")
@Validated
public class LookDataController {
    @Autowired
    private LookDataService lookDataService;

    @Autowired
    private SelectShopIdService selectShopIdService;

/*    @GetMapping("/getNewGoods")
    public Map getNewGoods(){
        List<MonthVO> list = new ArrayList<>();
        MonthVO monthVO = new MonthVO();

        monthVO.setLastMonth(100);
        monthVO.setThisMonth(200);

        Map map = new HashMap();
        map.put("code", 200);
        map.put("msg", "当月新商品");
        map.put("data",list);
        return map;
    }*/

    @ApiOperation("总销量")
    @GetMapping("/getTotalMoney")
    public Map getTotalMoney(HttpServletRequest request){
        String loginId = JwtUtil.getUsername(request.getAttribute("token1").toString());
        Integer shopid =this.selectShopIdService.getShopId(loginId);

        List<MonthVO> list = this.lookDataService.getTotalMoney(shopid);

        Map map = new HashMap();
        map.put("code", 200);
        map.put("msg", "总销量");
        map.put("data",list);
        return map;
    }

    @ApiOperation("订单")
    @GetMapping("/getOrder")
    public Map getOrder(HttpServletRequest request){
        String loginId = JwtUtil.getUsername(request.getAttribute("token1").toString());
        Integer shopid =this.selectShopIdService.getShopId(loginId);

        List<MonthVO> list = this.lookDataService.getAllOrder(shopid);

        Map map = new HashMap();
        map.put("code", 200);
        map.put("msg", "订单量");
        map.put("订单总量",list);
        return map;
    }

    @ApiOperation("销售额")
    @GetMapping("/getTimeAndMoneyVO")
    public Map getTimeAndMoneyVO(HttpServletRequest request){
        String loginId = JwtUtil.getUsername(request.getAttribute("token1").toString());
        Integer shopid =this.selectShopIdService.getShopId(loginId);

        List<TimeAndMoneyVO> list1 = this.lookDataService.getThisMonthMoneyAndTime(shopid);
        List<TimeAndMoneyVO> list2 = this.lookDataService.getLastMonthMoneyAndTime(shopid);

        Map map = new HashMap();

        map.put("code", 200);
        map.put("msg", "当月订单量");
        map.put("当月",list1);
        map.put("上月",list2);
        return map;
    }

    @ApiOperation("对应商品图")
    @GetMapping("/getGoods")
    public Map postGoodsPercent(HttpServletRequest request){
        String loginId = JwtUtil.getUsername(request.getAttribute("token1").toString());
        Integer shopid =this.selectShopIdService.getShopId(loginId);

        List<TotalGoodsAndMoneyVO> list1 = this.lookDataService.getTotalGoodsNumAndMoney(shopid);
        List<GoodsClassifyVO> list2 = this.lookDataService.getGoodsNum(shopid);


        Map map = new HashMap();
        map.put("code", 200);
        map.put("msg", "当月订单量");
        map.put("当月商品总销量",list1);
        map.put("当月对应商品销量",list2);
        return map;

    }

}
